package com.acceptable.qucun.user.mapper;

import com.acceptable.qucun.user.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.lang.NonNull;

import java.time.LocalDateTime;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 巴斯罗斯·K·赫斯洛利
 * @since 2021-08-29
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    User selectByEmail(@NonNull @Param("email") String email);
    User selectByUserId(@NonNull @Param("id") Integer id);
    int insert(User user);

    int recoveryAccountByEmail(@NonNull @Param("email") String email);

    int changePasswordByEmail(@NonNull @Param("email") String email,
                              @NonNull @Param("password") String password);

    void updateNormalInfo(@NonNull @Param("user") User user);

    @Update("UPDATE user SET email=#{destEmail} WHERE user_id=#{userId} ")
    int changeEmailByUserId(@NonNull @Param("destEmail") String email,
                            @NonNull @Param("userId") Integer userId);

    @Update("UPDATE user SET is_deleted=TRUE, delete_time=#{deleteTime} WHERE email=#{email}")
    int revokeAccount(@NonNull @Param("email") String email,
                      @NonNull @Param("deleteTime") LocalDateTime dateTime);

    @Delete("DELETE FROM user WHERE user_id=#{userId}")
    int deleteByUserId(@NonNull @Param("userId") Integer userId);
}
